home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / DR1.#1 PPC C⁄C++ ƒ / C++ Runtime ƒ / runtime.s < prev    next >
Text File  |  1994-02-04  |  10KB  |  366 lines

  1. #    MWRuntime.s    -    Runtime Support routines for Metrowerks C++ for PowerPC
  2. #
  3. #    Copyright © 1993 metrowerks inc.  All Rights Reserved.
  4. #
  5.  
  6. #
  7. #    Assembler Equates
  8. #
  9. .set r0,0; .set SP,1; .set RTOC,2; .set r3,3; .set r4,4; .set r5,5; .set r6,6; .set r7,7
  10. .set r8,8; .set r9,9; .set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14; .set r15,15
  11. .set r16,16; .set r17,17; .set r18,18; .set r19,19; .set r20,20; .set r21,21; .set r22,22; .set r23,23
  12. .set r24,24; .set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29; .set r30,30; .set r31,31
  13. .set fp0,0; .set fp1,1; .set fp2,2; .set fp3,3; .set fp4,4; .set fp5,5; .set fp6,6; .set fp7,7
  14. .set fp8,8; .set fp9,9; .set fp10,10; .set fp11,11; .set fp12,12; .set fp13,13; .set fp14,14; .set fp15,15
  15. .set fp16,16; .set fp17,17; .set fp18,18; .set fp19,19; .set fp20,20; .set fp21,21; .set fp22,22; .set fp23,23
  16. .set fp24,24; .set fp25,25; .set fp26,26; .set fp27,27; .set fp28,28; .set fp29,29; .set fp30,30; .set fp31,31
  17. .set cr0,0; .set cr1,1; .set cr2,2; .set cr3,3; .set cr4,4; .set cr5,5; .set cr6,6; .set cr7,7
  18. .set MQ,0; .set XER,1; .set FROM_RTCU,4; .set FROM_RTCL,5; .set FROM_DEC,6; .set LR,8; .set CTR,9; .set TID,17
  19. .set DSISR,18; .set DAR,19; .set TO_RTCU,20; .set TO_RTCL,21; .set TO_DEC,22; .set SDR_0,24; .set SDR_1,25; .set SRR_0,26
  20. .set SRR_1,27
  21. .set BO_dCTR_NZERO_AND_NOT,0; .set BO_dCTR_NZERO_AND_NOT_1,1; .set BO_dCTR_ZERO_AND_NOT,2; .set BO_dCTR_ZERO_AND_NOT_1,3
  22. .set BO_IF_NOT,4; .set BO_IF_NOT_1,5; .set BO_IF_NOT_2,6; .set BO_IF_NOT_3,7
  23. .set BO_dCTR_NZERO_AND,8; .set BO_dCTR_NZERO_AND_1,9; .set BO_dCTR_ZERO_AND,10; .set BO_dCTR_ZERO_AND_1,11
  24. .set BO_IF,12; .set BO_IF_1,13; .set BO_IF_2,14; .set BO_IF_3,15
  25. .set BO_dCTR_NZERO,16; .set BO_dCTR_NZERO_1,17; .set BO_dCTR_ZERO,18; .set BO_dCTR_ZERO_1,19
  26. .set BO_ALWAYS,20; .set BO_ALWAYS_1,21; .set BO_ALWAYS_2,22; .set BO_ALWAYS_3,23
  27. .set BO_dCTR_NZERO_8,24; .set BO_dCTR_NZERO_9,25; .set BO_dCTR_ZERO_8,26; .set BO_dCTR_ZERO_9,27
  28. .set BO_ALWAYS_8,28; .set BO_ALWAYS_9,29; .set BO_ALWAYS_10,30; .set BO_ALWAYS_11,31
  29. .set CR0_LT,0; .set CR0_GT,1; .set CR0_EQ,2; .set CR0_SO,3
  30. .set CR1_FX,4; .set CR1_FEX,5; .set CR1_VX,6; .set CR1_OX,7
  31. .set CR2_LT,8; .set CR2_GT,9; .set CR2_EQ,10; .set CR2_SO,11
  32. .set CR3_LT,12; .set CR3_GT,13; .set CR3_EQ,14; .set CR3_SO,15
  33. .set CR4_LT,16; .set CR4_GT,17; .set CR4_EQ,18; .set CR4_SO,19
  34. .set CR5_LT,20; .set CR5_GT,21; .set CR5_EQ,22; .set CR5_SO,23
  35. .set CR6_LT,24; .set CR6_GT,25; .set CR6_EQ,26; .set CR6_SO,27
  36. .set CR7_LT,28; .set CR7_GT,29; .set CR7_EQ,30; .set CR7_SO,31
  37.  
  38.  
  39. #
  40. #    Private Data
  41. #
  42.         .csect    __constants{RO}
  43.         .long    0x43300000            # integer->floating conversion constant
  44.         .long    0x80000000
  45.         .long    0x43300000            # unsigned->floating conversion constant
  46.         .long    0x00000000
  47.         .long    0x00000000            # 0.0
  48.         .long    0x00000000
  49.         .long    0x41F00000            # 2**32
  50.         .long    0x00000000
  51.         .long    0x41E00000            # 2**31
  52.         .long    0x00000000
  53.         
  54.         .csect    __argv{RW}
  55.         .long    0
  56.  
  57. #
  58. #    TOC pointers
  59. #
  60.         .toc
  61. T.__constants:
  62.         .tc        __constants{TC}, __constants{RO}
  63.  
  64.  
  65. #    __cvt_int2single    -    convert 32-bit integer to floating-point single
  66. #
  67. #    Convert the 32-bit integer in R3 to a floating-point single and return
  68. #    the result in F1.
  69. #
  70.         .csect    .__cvt_int2single{PR}
  71.         .globl    .__cvt_int2single{PR}
  72.         lwz        r4,T.__constants(RTOC)
  73.         xoris    r0,r3,0x8000
  74.         lfd        fp0,0(r4)            # fp0 = integer->floating conversion constant
  75.         stw        r0,-4(SP)
  76.         lis        r0,0x4330
  77.         stw        r0,-8(SP)
  78.         lfd        fp1,-8(SP)
  79.         fsubs    fp1,fp1,fp0
  80.         blr
  81.  
  82.  
  83. #    __cvt_int2double    -    convert 32-bit integer to floating-point double
  84. #
  85. #    Convert the 32-bit integer in R3 to a floating-point double and return
  86. #    the result in F1.
  87. #
  88.         .csect    .__cvt_int2double{PR}        
  89.         .globl    .__cvt_int2double{PR}
  90.         lwz        r4,T.__constants(RTOC)
  91.         xoris    r0,r3,0x8000
  92.         lfd        fp0,0(r4)            # fp0 = integer->floating conversion constant
  93.         stw        r0,-4(SP)
  94.         lis        r0,0x4330
  95.         stw        r0,-8(SP)
  96.         lfd        fp1,-8(SP)
  97.         fsub    fp1,fp1,fp0
  98.         blr
  99.  
  100.  
  101. #    __cvt_uns2single    -    convert 32-bit unsigned to floating-point single
  102. #
  103. #    Convert the 32-bit integer in R3 to a floating-point single and return
  104. #    the result in F1.
  105. #
  106.         .csect    .__cvt_uns2single{PR}
  107.         .globl    .__cvt_uns2single{PR}
  108.         lwz        r4,T.__constants(RTOC)
  109.         stw        r3,-4(SP)
  110.         lfd        fp0,8(r4)            # fp0 = unsigned->floating conversion constant
  111.         lis        r0,0x4330
  112.         stw        r0,-8(SP)
  113.         lfd        fp1,-8(SP)
  114.         fsubs    fp1,fp1,fp0
  115.         blr
  116.  
  117.  
  118. #    __cvt_uns2double    -    convert 32-bit unsigned to floating-point double
  119. #
  120. #    Convert the 32-bit integer in R3 to a floating-point single and return
  121. #    the result in F1.
  122. #
  123.         .csect    .__cvt_uns2double{PR} 
  124.         .globl    .__cvt_uns2double{PR}
  125.         lwz        r4,T.__constants(RTOC)
  126.         stw        r3,-4(SP)
  127.         lfd        fp0,8(r4)            # fp0 = unsigned->floating conversion constant
  128.         lis        r0,0x4330
  129.         stw        r0,-8(SP)
  130.         lfd        fp1,-8(SP)
  131.         fsub    fp1,fp1,fp0
  132.         blr
  133.  
  134. #    __cvt_fp2unsigned    -    convert floating-point to 32-bit unsigned integer
  135. #
  136. #    Convert the floating-point value in F1 to a 32-bit unsigned integer
  137. #    and return the result in R3.
  138. #
  139. #    This routine is copied from the Motorola PowerPC 602 Users Manual, pg. F-1.
  140. #
  141.         .globl    .__cvt_fp2unsigned{PR}
  142.         .csect    .__cvt_fp2unsigned{PR}
  143.         
  144.         lwz        r4,T.__constants(RTOC)
  145.         li        r3,0                # r3 = 0
  146.         lfd        fp0,16(r4)            # fp0 = 0.0
  147.         lfd        fp3,24(r4)            # fp3 = 2**32
  148.         lfd        fp4,32(r4)            # fp4 = 2**31
  149.         fcmpu    cr0,fp1,fp0            # cr0 = compare(fp1,0.0)
  150.         fcmpu    cr6,fp1,fp3            # cr6 = compare(fp1,2**32)
  151.         bltlr    cr0                    # return 0x00000000 if input was < 0.0
  152.         addi    r3,r3,-1
  153.         bgelr    cr6                    # return 0xFFFFFFFF if input was >= 2**32
  154.         fcmpu    cr7,fp1,fp4            # cr7 = compare(fp1,2**31)
  155.         fmr        fp2,fp1
  156.         blt        cr7,$+8                # use fp1 if < 2**31
  157.         fsub    fp2,fp1,fp4            # subtract 2**31
  158.         fctiwz    fp2,fp2                # convert float to 8-byte integer
  159.         stfd    fp2,-8(SP)            # store 8-byte integer
  160.         lwz        r3,-4(SP)            # load 4-byte integer
  161.         bltlr    cr7
  162.         addis    r3,r3,-32768        # add 2**31 if input was >= 2**31
  163.         blr
  164.  
  165.  
  166. #    __ptr_glue        -    glue for function calls through pointers
  167. #
  168. #    Call the function whose 2-word TVector address is in R12.
  169. #
  170.         .csect    .__ptr_glue{GL}
  171.         .globl    .__ptr_glue{GL}
  172.         lwz        r0,0(r12)
  173.         stw        RTOC,20(SP)
  174.         mtctr    r0
  175.         lwz        RTOC,4(r12)
  176.         bctr
  177.         
  178.         
  179. #    _ptrgl            -    AIX & Lucid compatible version of __ptr_glue
  180. #
  181. #    Call the function whose 3-word TVector address is in R11.
  182. #
  183.         .csect    ._ptrgl{GL}
  184.         .globl    ._ptrgl{GL}
  185.         lwz        r0,0(r11)
  186.         stw        RTOC,20(SP)
  187.         mtctr    r0
  188.         lwz        RTOC,4(r11)
  189.         lwz        r11,8(r11)
  190.         bctr
  191.         
  192.         
  193. #    __blockmove        -    move (unaligned) block of data
  194. #
  195. #    Move the # bytes in R5 from the address in R4 to the address in R3.
  196. #    The # bytes is at least 128. We move the data in 32-byte chunks.
  197. #
  198.         .csect    .__blockmove{PR}
  199.         .globl    .__blockmove{PR}
  200.  
  201. #    save some nonvolatile registers that we need
  202.  
  203.         stw        r13,-4(SP)
  204.         stw        r14,-8(SP)
  205.         stw        r15,-12(SP)
  206.  
  207. #    set XER = chunk size
  208.  
  209.         li        r7,32
  210.         mtxer    r7
  211.  
  212. #    set CTR = #chunks to move
  213.  
  214.         rlwinm    r8,r5,27,5,31
  215.         mtctr    r8
  216.  
  217. #    set    R5 = remainder
  218.     
  219.         rlwinm.    r5,r5,0,27,31    #    cr0(eq) = no remainder
  220.         
  221. #    copy 32-byte chunks
  222.  
  223.         li        r6,0
  224. loop:    lswx    r8,r6,r4
  225.         stswx    r8,r6,r3
  226.         addi    r6,r6,32
  227.         bdnz    loop
  228.         beq        exit            #    return if no remainder
  229.         
  230. #    copy remainder
  231.  
  232.         mtxer    r5
  233.         lswx    r8,r6,r4
  234.         stswx    r8,r6,r3
  235.  
  236. #    restore registers and return
  237.  
  238. exit:    lwz        r15,-12(SP)
  239.         lwz        r14,-8(SP)
  240.         lwz        r13,-4(SP)
  241.         blr
  242.  
  243.  
  244. #
  245. #    __save_fpr_XX    -    save FPR's XX through 31
  246. #
  247.         .csect    .__save_fpr{PR}
  248.         .globl    .__save_fpr{PR}
  249.         .globl    .__save_fpr_14
  250.         .globl    .__save_fpr_15
  251.         .globl    .__save_fpr_16
  252.         .globl    .__save_fpr_17
  253.         .globl    .__save_fpr_18
  254.         .globl    .__save_fpr_19
  255.         .globl    .__save_fpr_20
  256.         .globl    .__save_fpr_21
  257.         .globl    .__save_fpr_22
  258.         .globl    .__save_fpr_23
  259.         .globl    .__save_fpr_24
  260.         .globl    .__save_fpr_25
  261.         .globl    .__save_fpr_26
  262.         .globl    .__save_fpr_27
  263.         .globl    .__save_fpr_28
  264.         .globl    .__save_fpr_29
  265.         .globl    .__save_fpr_30
  266.         .globl    .__save_fpr_31
  267. .__save_fpr_14:
  268.         stfd    fp14,-144(SP)
  269. .__save_fpr_15:
  270.         stfd    fp15,-136(SP)
  271. .__save_fpr_16:
  272.         stfd    fp16,-128(SP)
  273. .__save_fpr_17:
  274.         stfd    fp17,-120(SP)
  275. .__save_fpr_18:
  276.         stfd    fp18,-112(SP)
  277. .__save_fpr_19:
  278.         stfd    fp19,-104(SP)
  279. .__save_fpr_20:
  280.         stfd    fp20,-96(SP)
  281. .__save_fpr_21:
  282.         stfd    fp21,-88(SP)
  283. .__save_fpr_22:
  284.         stfd    fp22,-80(SP)
  285. .__save_fpr_23:
  286.         stfd    fp23,-72(SP)
  287. .__save_fpr_24:
  288.         stfd    fp24,-64(SP)
  289. .__save_fpr_25:
  290.         stfd    fp25,-56(SP)
  291. .__save_fpr_26:
  292.         stfd    fp26,-48(SP)
  293. .__save_fpr_27:
  294.         stfd    fp27,-40(SP)
  295. .__save_fpr_28:
  296.         stfd    fp28,-32(SP)
  297. .__save_fpr_29:
  298.         stfd    fp29,-24(SP)
  299. .__save_fpr_30:
  300.         stfd    fp30,-16(SP)
  301. .__save_fpr_31:
  302.         stfd    fp31,-8(SP)
  303.         blr
  304.         
  305.  
  306. #
  307. #    __restore_fpr_XX    -    restore FPR's XX through 31
  308. #
  309.         .csect    .__restore_fpr{PR}
  310.         .globl    .__restore_fpr{PR}
  311.         .globl    .__restore_fpr_14
  312.         .globl    .__restore_fpr_15
  313.         .globl    .__restore_fpr_16
  314.         .globl    .__restore_fpr_17
  315.         .globl    .__restore_fpr_18
  316.         .globl    .__restore_fpr_19
  317.         .globl    .__restore_fpr_20
  318.         .globl    .__restore_fpr_21
  319.         .globl    .__restore_fpr_22
  320.         .globl    .__restore_fpr_23
  321.         .globl    .__restore_fpr_24
  322.         .globl    .__restore_fpr_25
  323.         .globl    .__restore_fpr_26
  324.         .globl    .__restore_fpr_27
  325.         .globl    .__restore_fpr_28
  326.         .globl    .__restore_fpr_29
  327.         .globl    .__restore_fpr_30
  328.         .globl    .__restore_fpr_31
  329. .__restore_fpr_14:
  330.         lfd        fp14,-144(SP)
  331. .__restore_fpr_15:
  332.         lfd        fp15,-136(SP)
  333. .__restore_fpr_16:
  334.         lfd        fp16,-128(SP)
  335. .__restore_fpr_17:
  336.         lfd        fp17,-120(SP)
  337. .__restore_fpr_18:
  338.         lfd        fp18,-112(SP)
  339. .__restore_fpr_19:
  340.         lfd        fp19,-104(SP)
  341. .__restore_fpr_20:
  342.         lfd        fp20,-96(SP)
  343. .__restore_fpr_21:
  344.         lfd        fp21,-88(SP)
  345. .__restore_fpr_22:
  346.         lfd        fp22,-80(SP)
  347. .__restore_fpr_23:
  348.         lfd        fp23,-72(SP)
  349. .__restore_fpr_24:
  350.         lfd        fp24,-64(SP)
  351. .__restore_fpr_25:
  352.         lfd        fp25,-56(SP)
  353. .__restore_fpr_26:
  354.         lfd        fp26,-48(SP)
  355. .__restore_fpr_27:
  356.         lfd        fp27,-40(SP)
  357. .__restore_fpr_28:
  358.         lfd        fp28,-32(SP)
  359. .__restore_fpr_29:
  360.         lfd        fp29,-24(SP)
  361. .__restore_fpr_30:
  362.         lfd        fp30,-16(SP)
  363. .__restore_fpr_31:
  364.         lfd        fp31,-8(SP)
  365.         blr
  366.